package com.example.walkera.rtsp_android_client.function;

import android.content.Context;
import android.content.SharedPreferences;

import com.example.walkera.rtsp_android_client.global.GlobalInfo;

/**
 * Created by kaifa@lihaiping1603@aliyun.com on 2017/2/8.
 */
public class CameraInfoSharedPreferencesHelper {

    private final static String TAG="CameraInfoSharedPreferencesHelper";


    private static CameraInfoSharedPreferencesHelper instance = new CameraInfoSharedPreferencesHelper();

    public static CameraInfoSharedPreferencesHelper getInstance() {
        if (instance == null) {
            instance = new CameraInfoSharedPreferencesHelper();
        }
        return instance;
    }

    private SharedPreferences mSharedPref=null;
    private SharedPreferences.Editor mSharedPrefEditor=null;

    public void createCameraInfoTable(Context context){
        //生成一个存储文件
        if (mSharedPref==null){
            mSharedPref=context.getSharedPreferences("airplane_info",Context.MODE_PRIVATE);
        }
        if (mSharedPrefEditor==null){
            mSharedPrefEditor=mSharedPref.edit();
        }
    }

    private final static String mStrAirpalneTypeKey="AirplaneName";
    public void writeAirPlaneName(String strAirName){
        if (mSharedPrefEditor==null){
            createCameraInfoTable(GlobalInfo.getInstance().getAppContext());
        }
        mSharedPrefEditor.putString(mStrAirpalneTypeKey,strAirName);
        mSharedPrefEditor.commit();
    }

    public String readAirPlaneName(){
        return mSharedPref.getString(mStrAirpalneTypeKey,"");
    }
}
